﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using WS.EKA.Business.Dal;
using WS.EKA.Business.Model;
using WS.EKA.UI.Business;

namespace WS.EKA.Web.UI.Demo
{
    public partial class ITNotienceManagement : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
        }

        protected void OndutySubmit_Click(object sender, EventArgs e)
        {
            //string ErrorMsg = string.Empty;
            //string Monitor = this.Monitor.Text;
            //if (string.IsNullOrEmpty(Monitor))
            //{
            //    ErrorMsg = "请将IT公告的表单填写完整";
            //}
            //string System = this.System.Text;
            //if (string.IsNullOrEmpty(System))
            //{
            //    ErrorMsg = "请将IT公告的表单填写完整";
            //}
            //string DB = this.DB.Text;
            //if (string.IsNullOrEmpty(DB))
            //{
            //    ErrorMsg= "请将IT公告的表单填写完整";
            //}
            //string App = this.App.Text;
            //if (string.IsNullOrEmpty(App))
            //{
            //    ErrorMsg = "请将IT公告的表单填写完整";
            //}
            //string NetWork = this.NetWork.Text;
            //if (string.IsNullOrEmpty(NetWork))
            //{
            //    ErrorMsg = "请将IT公告的表单填写完整";
            //}
            //if (!string.IsNullOrEmpty(ErrorMsg))
            //{
            //    WebMessageBox(this, ErrorMsg);
            //    return;
            //}
            //string IsDayWork = this.DutyType.SelectedValue;
            //ITAnnouncementAccess.AddOnDuty(new OnDuty()
            //{
            //    App = App.Replace("\r\n","<br/>"),
            //    DB = DB.Replace("\r\n", "<br/>"),
            //    Monitor = Monitor.Replace("\r\n", "<br/>"),
            //    NetWork = NetWork.Replace("\r\n", "<br/>"),
            //    System = System.Replace("\r\n", "<br/>"),
            //    DutyTime = DateTime.Now,
            //    IsDayWork = IsDayWork == "1" ? true : false
            //});
            ////出触发值班人员推送
            //ClientDataSourceBridge.Push(WebSocketClientType.ITNotice_OnDuty);
            //WebMessageBox(this, IsDayWork == "1" ? "白班人员添加成功" : "晚班人员添加成功");
        }

        protected void LatestImportantTaskSubmit_Click(object sender, EventArgs e)
        {
            string ErrorMsg = string.Empty;
            string LatestImportantTask = this.LatestImportantTask.Text;
            if (string.IsNullOrEmpty(LatestImportantTask))
            {
                ErrorMsg= "请将最近重要作业的表单填写完整";
            }
            if (!string.IsNullOrEmpty(ErrorMsg))
            {
                WebMessageBox(this, ErrorMsg);
                return;
            }
            ITAnnouncementAccess.AddLatestImportantTask(new LatestImportantTask()
            {
                Content = LatestImportantTask,
                CreateTime = DateTime.Now
            });
            //出触发值班人员推送
            ClientDataSourceBridge.Push(WebSocketClientType.ITNotice_LatestImportantTask);
            WebMessageBox(this, "最近重要作业发布成功");
        }

        protected void AnnounceMentSubmit_Click(object sender, EventArgs e)
        {
            string ErrorMsg = string.Empty;
            string AnnounceMent = this.AnnounceMent.Text;
            if (string.IsNullOrEmpty(AnnounceMent))
            {
                ErrorMsg = "请将通知公告的表单填写完整";
            }
            if (!string.IsNullOrEmpty(ErrorMsg))
            {
                WebMessageBox(this, ErrorMsg);
                return;
            }
            ITAnnouncementAccess.AddAnnounceMent(new AnnounceMent()
            {
                Content = AnnounceMent,
                CreateTime = DateTime.Now
            });
            //出触发值班人员推送
            ClientDataSourceBridge.Push(WebSocketClientType.ITNotice_AnnounceMent);
            WebMessageBox(this, "通知公告发布成功");
        }

        protected void LatestImportantJobSubmit_Click(object sender, EventArgs e)
        {
            string ErrorMsg = string.Empty;
            string LatestImportantJob = this.LatestImportantJob.Text;
            if (string.IsNullOrEmpty(LatestImportantJob))
            {
                ErrorMsg = "请将近期重要工作的表单填写完整";
            }
            if (!string.IsNullOrEmpty(ErrorMsg))
            {
                WebMessageBox(this, ErrorMsg);
                return;
            }
            //ITAnnouncementAccess.AddLatestImportantJob(new LatestImportantJob()
            //{
            //    Content = LatestImportantJob,
            //    CreateTime = DateTime.Now
            //});
            ////出触发值班人员推送
            //ClientDataSourceBridge.Push(WebSocketClientType.ITNotice_LatestImportantJob);
            WebMessageBox(this, "近期重要工作发布成功");
        }

        private void WebMessageBox(System.Web.UI.Page page, string msg, string callback = null)
        {
            if (string.IsNullOrEmpty(callback))
                PageRegisterStartupScript(page, string.Format("<script type=\"text/javascript\">ShowMessage('{0}')</script>", msg));
            else
                PageRegisterStartupScript(page, string.Format("<script type=\"text/javascript\">ShowMessage('{0}',{1})</script>", msg, callback));
        }

        private void PageRegisterStartupScript(System.Web.UI.Page page, string script)
        {
            page.ClientScript.RegisterStartupScript(page.GetType(), "", script);
        }

    }
}